```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kafka消息队列技术指南</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f8fafc;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .code-block {
            background-color: #282c34;
            color: #abb2bf;
            border-radius: 6px;
            padding: 1rem;
            overflow-x: auto;
        }
        .card {
            transition: all 0.3s ease;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-bottom: 0.5rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 3px;
            background: linear-gradient(90deg, #667eea, #764ba2);
        }
        .icon-box {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 1rem;
        }
        .diagram-container {
            background-color: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">Kafka消息队列技术指南</h1>
                    <p class="text-xl mb-6 opacity-90">分布式、高吞吐量的发布-订阅消息系统</p>
                    <div class="flex space-x-4">
                        <a href="#intro" class="bg-white text-indigo-700 px-6 py-2 rounded-full font-medium hover:bg-gray-100 transition">开始探索</a>
                        <a href="#quick-start" class="border-2 border-white text-white px-6 py-2 rounded-full font-medium hover:bg-white hover:bg-opacity-10 transition">快速开始</a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1658486263286-6f126be5-d976-4797-a350-9ba8e387ace5.png" alt="Kafka架构" class="rounded-lg shadow-xl w-full max-w-md">
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction Section -->
        <section id="intro" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">消息队列概述</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="mb-6 text-gray-700">消息队列(Message Queue)是一种提供消息传送服务的系统，依赖于多个支持组件来处理连接服务、消息路由、持久性、安全性和日志记录等功能。消息服务器可以使用一个或多个代理实例。</p>
                    
                    <div class="card bg-white p-6 mb-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-indigo-100 text-indigo-600">
                                <i class="fas fa-exchange-alt"></i>
                            </div>
                            <span>消息队列分类</span>
                        </h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-indigo-600">生产者消费者模式</h4>
                                <p class="text-gray-600">生产者生产消息放到队列里，多个消费者同时监听队列，谁先抢到消息谁就会从队列中取走消息；即对于每个消息只能被最多一个消费者拥有。</p>
                            </div>
                            <div>
                                <h4 class="font-medium text-indigo-600">发布者订阅者模式</h4>
                                <p class="text-gray-600">发布者生产消息放到队列里，多个监听队列的消费者都会收到同一份消息；即正常情况下每个消费者收到的消息应该都是一样的。</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-purple-100 text-purple-600">
                                <i class="fas fa-info-circle"></i>
                            </div>
                            <span>Kafka简介</span>
                        </h3>
                        <p class="text-gray-700 mb-4">Kafka是分布式发布-订阅消息系统，最初由LinkedIn公司开发，使用Scala语言编写，之后成为Apache项目的一部分。Kafka集群中没有"中心主节点"的概念，所有服务器都是对等的。</p>
                        <div class="space-y-3">
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>高吞吐量：即使是非常普通的硬件kafka也可以支持每秒数十万的消息</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>持久化：通过O(1)的磁盘数据结构提供消息的持久化，即使数以TB的消息存储也能够保持长时间的稳定性能</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>分布式：支持通过Kafka服务器和消费机集群来分区消息</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Use Cases Section -->
        <section id="use-cases" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Kafka使用场景</h2>
            <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="card bg-white p-6">
                    <div class="text-indigo-600 text-3xl mb-4">
                        <i class="fas fa-clipboard-list"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">日志收集</h3>
                    <p class="text-gray-600">公司可以用Kafka收集各种服务的log，通过kafka以统一接口服务的方式开放给各种consumer，如hadoop、Hbase、Solr等。</p>
                </div>
                
                <div class="card bg-white p-6">
                    <div class="text-purple-600 text-3xl mb-4">
                        <i class="fas fa-envelope"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">消息系统</h3>
                    <p class="text-gray-600">解耦生产和消费者、缓存消息等，实现系统间的异步通信。</p>
                </div>
                
                <div class="card bg-white p-6">
                    <div class="text-blue-600 text-3xl mb-4">
                        <i class="fas fa-user"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">用户活动跟踪</h3>
                    <p class="text-gray-600">记录web用户或app用户的各种活动，如浏览网页、搜索、点击等活动，用于实时监控分析或离线分析挖掘。</p>
                </div>
                
                <div class="card bg-white p-6">
                    <div class="text-green-600 text-3xl mb-4">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">运营指标</h3>
                    <p class="text-gray-600">记录运营监控数据，收集各种分布式应用的数据，生产各种操作的集中反馈，如报警和报告。</p>
                </div>
                
                <div class="card bg-white p-6">
                    <div class="text-red-600 text-3xl mb-4">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">限流</h3>
                    <p class="text-gray-600">高并发场景下(如双11)，可以把请求写入到队列中，系统分批拉取消息慢慢处理，实现流量削峰。</p>
                </div>
            </div>
        </section>

        <!-- Quick Start Section -->
        <section id="quick-start" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">快速开始</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-blue-100 text-blue-600 mr-4">
                            <i class="fas fa-terminal"></i>
                        </div>
                        <span>二进制包安装</span>
                    </h3>
                    
                    <div class="space-y-6">
                        <div>
                            <h4 class="font-medium text-lg mb-2">1. 下载Kafka</h4>
                            <div class="code-block">
                                <code>wget https://archive.apache.org/dist/kafka/2.4.0/kafka_2.11-2.4.0.tgz</code>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-lg mb-2">2. 解压缩</h4>
                            <div class="code-block">
                                <code>tar -zxf kafka_2.11-2.4.0.tgz</code>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-lg mb-2">3. 修改配置</h4>
                            <div class="code-block">
                                <pre># broker的编号，如果kafka集群了，则每个broker的编号需要设置不同
broker.id=0
# 对外提供服务的入口地址
listeners=PLAINTEXT://0.0.0.0:9092
# 外部代理地址  
advertised.listeners=PLAINTEXT://192.168.147.200:9092
# 存放日志文件的地址
log.dirs=/tmp/kafka-logs
# kafka需要ZK的地址
zookeeper.connect=localhost:2181
# 全局分区数量
num.partitions=1</pre>
                            </div>
                        </div>
                        
                        <div>
                            <h4 class="font-medium text-lg mb-2">4. 启动Kafka</h4>
                            <div class="code-block">
                                <code>./kafka-server-start.sh -daemon ../config/server.properties</code>
                            </div>
                            <p class="text-gray-600 mt-2 text-sm">daemon：后台运行服务<br>../config/server.properties：kafka配置文件的位置</p>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-green-100 text-green-600 mr-4">
                            <i class="fab fa-docker"></i>
                        </div>
                        <span>Docker安装</span>
                    </h3>
                    
                    <div class="code-block mb-6">
                        <pre>version: '2'
services:
  zookeeper:
    container_name: zk
    restart: always
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    container_name: kafka
    restart: always
    image: wurstmeister/kafka
    volumes: 
        - ./kafka/localtime:/etc/localtime ## 挂载位置（kafka镜像和宿主机器之间时间保持一直）
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.147.133   ## 修改:宿主机IP
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181       ## 卡夫卡运行是基于zookeeper的
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_LOG_RETENTION_HOURS: 120
      KAFKA_MESSAGE_MAX_BYTES: 10000000
      KAFKA_REPLICA_FETCH_MAX_BYTES: 10000000
      KAFKA_GROUP_MAX_SESSION_TIMEOUT_MS: 60000
      KAFKA_NUM_PARTITIONS: 3
      KAFKA_DELETE_RETENTION_MS: 1000</pre>
                    </div>
                    
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-yellow-100 text-yellow-600 mr-4">
                            <i class="fas fa-project-diagram"></i>
                        </div>
                        <span>ZK和Kafka的关系</span>
                    </h3>
                    
                    <div class="diagram-container mb-6">
                        <div class="mermaid">
                            graph LR
                                ZK[ZooKeeper] -->|管理元数据| K1[Kafka Broker 1]
                                ZK -->|管理元数据| K2[Kafka Broker 2]
                                ZK -->|管理元数据| K3[Kafka Broker 3]
                                ZK -->|协调消费者群组| C1[Consumer Group]
                                ZK -->|协调消费者群组| C2[Consumer Group]
                        </div>
                    </div>
                    
                    <p class="text-gray-700">ZooKeeper是一个开源的分布式协调服务，Kafka使用ZooKeeper来管理集群的元数据和协调工作。Kafka的Broker会将集群的元数据信息（如主题、分区等）注册到ZooKeeper上，并通过ZooKeeper进行领导者选举、分区分配等协调工作。</p>
                </div>
            </div>
        </section>

        <!-- Basic Operations Section -->
        <section id="operations" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Kafka基本操作</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-6 flex items-center">
                        <div class="icon-box bg-indigo-100 text-indigo-600 mr-4">
                            <i class="fas fa-list"></i>
                        </div>
                        <span>Topic命令</span>
                    </h3>
                    
                    <div class="space-y-6">
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">1. 创建Topic</h4>
                            <div class="code-block">
                                <code>bin/kafka-topics.sh --zookeeper localhost:2181 --create --topic test01-topic --partitions 1 --replication-factor 1</code>
                            </div>
                        </div>
                        
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">2. 列出所有topic</h4>
                            <div class="code-block">
                                <code>bin/kafka-topics.sh --zookeeper localhost:2181 --list</code>
                            </div>
                        </div>
                        
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">3. 查看topic分区和副本</h4>
                            <div class="code-block">
                                <code>bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test01-topic</code>
                            </div>
                        </div>
                        
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">4. 删除Topic</h4>
                            <div class="code-block">
                                <code>bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic test02-topic</code>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-6 flex items-center">
                        <div class="icon-box bg-purple-100 text-purple-600 mr-4">
                            <i class="fas fa-exchange-alt"></i>
                        </div>
                        <span>生产消费命令</span>
                    </h3>
                    
                    <div class="space-y-6">
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">1. 发送消息</h4>
                            <div class="code-block">
                                <code>bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test01-topic</code>
                            </div>
                        </div>
                        
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">2. 消费消息</h4>
                            <div class="code-block">
                                <code>bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test01-topic</code>
                            </div>
                        </div>
                        
                        <div class="card bg-white p-6">
                            <h4 class="font-medium text-lg mb-2">3. 从头开始获取消息</h4>
                            <div class="code-block">
                                <code>bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test01-topic --from-beginning</code>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Spring Boot Integration -->
        <section id="spring-boot" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Spring Boot整合Kafka</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-green-100 text-green-600 mr-4">
                            <i class="fas fa-leaf"></i>
                        </div>
                        <span>1. 导入依赖</span>
                    </h3>
                    
                    <div class="code-block">
                        <pre>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.kafka&lt;/groupId&gt;
    &lt;artifactId&gt;spring-kafka&lt;/artifactId&gt;
&lt;/dependency&gt;</pre>
                    </div>
                    
                    <h3 class="text-2xl font-semibold mt-8 mb-4 flex items-center">
                        <div class="icon-box bg-blue-100 text-blue-600 mr-4">
                            <i class="fas fa-cog"></i>
                        </div>
                        <span>2. YML配置</span>
                    </h3>
                    
                    <div class="code-block">
                        <pre>spring:
  kafka:
    bootstrap-servers: 192.168.147.200:9092 # 设置 Kafka Broker 地址
    producer: # 消息提供者key和value序列化方式
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
      retries: 3 # 生产者发送失败时，重试发送的次数
    consumer: # 消费端反序列化方式
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      group-id: demo # 消费者组ID</pre>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-yellow-100 text-yellow-600 mr-4">
                            <i class="fas fa-paper-plane"></i>
                        </div>
                        <span>3. 提供者发送消息</span>
                    </h3>
                    
                    <div class="code-block mb-6">
                        <pre>@Autowired
private KafkaTemplate kafkaTemplate;

@Test
void contextLoads() {
    ListenableFuture listenableFuture = kafkaTemplate.send("test01-topic", "Hello Wolrd test");
    System.out.println("发送完成");
}</pre>
                    </div>
                    
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <div class="icon-box bg-purple-100 text-purple-600 mr-4">
                            <i class="fas fa-headphones"></i>
                        </div>
                        <span>4. 消费端监听消息</span>
                    </h3>
                    
                    <div class="code-block">
                        <pre>@Component
public class TopicConsumer {

    @KafkaListener(topics = "test01-topic")
    public void readMsg(String msg){
        System.out.println("msg = " + msg);
    }
}</pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advanced Topics -->
        <section id="advanced" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">高级主题</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card bg-white p-6 mb-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-red-100 text-red-600 mr-4">
                                <i class="fas fa-users"></i>
                            </div>
                            <span>消费组</span>
                        </h3>
                        <p class="text-gray-700 mb-4">同一时刻，一条消息只能被组中的一个消费者实例消费。消费者组订阅一个主题，意味着主题下的所有分区都会被组中的消费者消费到，并且主题下的每个分区只从属于组中的一个消费者。</p>
                        
                        <div class="diagram-container">
                            <div class="mermaid">
                                graph LR
                                    P1[Partition 1] --> C1[Consumer 1]
                                    P2[Partition 2] --> C2[Consumer 2]
                                    P3[Partition 3] --> C3[Consumer 3]
                                    P4[Partition 4] --> C1
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-indigo-100 text-indigo-600 mr-4">
                                <i class="fas fa-exchange-alt"></i>
                            </div>
                            <span>消息发送模式</span>
                        </h3>
                        
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-indigo-600">同步发送</h4>
                                <div class="code-block">
                                    <pre>ListenableFuture future = kafkaTemplate.send("demo02-topic", msg);
System.out.println("消息已发送");
Object o = future.get(); // 阻塞主线程，直到消息发送成功
System.out.println("消息发送完成");</pre>
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-indigo-600">异步发送</h4>
                                <div class="code-block">
                                    <pre>ListenableFuture future = kafkaTemplate.send("demo02-topic", msg);
future.addCallback(new ListenableFutureCallback() {
    @Override
    public void onFailure(Throwable ex) {
        System.out.println("消息发送失败:" + ex);
    }
    @Override
    public void onSuccess(Object result) {
        System.out.println("消息发送成功:" + result);
    }
});</pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6 mb-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-green-100 text-green-600 mr-4">
                                <i class="fas fa-boxes"></i>
                            </div>
                            <span>批量消息处理</span>
                        </h3>
                        
                        <div class="space-y-4">
                            <p class="text-gray-700">Kafka提供的批量发送消息，它提供了一个RecordAccumulator消息收集器，将发送给相同Topic的相同Partition分区的消息收集在一起，当满足条件时候，一次性批量发送。</p>
                            
                            <div>
                                <h4 class="font-medium text-green-600">YML配置</h4>
                                <div class="code-block">
                                    <pre>spring:
  kafka:
    producer:
      batch-size: 16384 # 每次批量发送消息的最大数量
      buffer-memory: 33554432 # 每次批量发送消息的最大内存
      properties:
        linger.ms: 1000 # 等待时间
    consumer:
      fetch-max-wait: 10000 # poll阻塞的最大时长
      fetch-min-size: 10 # poll一次拉取的最小数据量
      max-poll-records: 100 # poll一次拉取的最大数量
    listener:
      type: BATCH # 监听器类型为BATCH，批量消费</pre>
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-green-600">批量消费者</h4>
                                <div class="code-block">
                                    <pre>@KafkaListener(topics = "demo02-topic", groupId = "batchConsumer")
public void batchConsumer(List&lt;String&gt; list) {
    System.out.println("接收到的消息数量: " + list.size());
}</pre>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-purple-100 text-purple-600 mr-4">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <span>分区机制</span>
                        </h3>
                        
                        <p class="text-gray-700 mb-4">Kafka的消息组织方式是三级结构：主题 - 分区 - 消息，每个主题下的每条消息只会保存在一个分区中。分区的作用是提供负载均衡能力，实现系统的高伸缩性。</p>
                        
                        <div class="space-y-3">
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>多Partition分布式存储，利于集群数据的均衡</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>并发读写，加快读写速度</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                                <span>加快数据恢复的速率：当某台机器挂了，每个Topic仅需恢复一部分的数据</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Kafka Eagle Section -->
        <section id="kafka-eagle" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Kafka监控工具 - Kafka Eagle</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-blue-100 text-blue-600 mr-4">
                                <i class="fas fa-eye"></i>
                            </div>
                            <span>Kafka Eagle简介</span>
                        </h3>
                        <p class="text-gray-700 mb-4">Kafka Eagle是一款用于监控和管理Apache Kafka的完全开源系统，提供了完善的管理页面，可以方便地管理和可视化Kafka集群的一些信息，例如Broker详情、性能指标趋势、Topic集合、消费者信息等。</p>
                        
                        <div class="space-y-3 mb-4">
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>展示Kafka集群的Broker数、Topic数、Consumer数等关键指标</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>主题创建、主题管理、主题预览、KSQL查询主题等</span>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                                <span>监控不同消费者组中的Topic被消费的详情</span>
                            </div>
                        </div>
                        
                        <a href="https://www.kafka-eagle.org/" class="text-blue-600 hover:text-blue-800 font-medium flex items-center">
                            <i class="fas fa-external-link-alt mr-2"></i>
                            访问Kafka Eagle官网
                        </a>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-green-100 text-green-600 mr-4">
                                <i class="fas fa-download"></i>
                            </div>
                            <span>安装与配置</span>
                        </h3>
                        
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-green-600">1. 下载</h4>
                                <div class="code-block">
                                    <code>https://github.com/smartloli/EFAK/releases/tag/v2.0.4</code>
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-green-600">2. 解压安装</h4>
                                <div class="code-block">
                                    <pre>tar -zxvf xxxxxx
mv xxxx kafka-eagle</pre>
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-green-600">3. 配置环境变量</h4>
                                <div class="code-block">
                                    <pre>vim /etc/profile 

# profile
export KE_HOME=/opt/kafka/kafka-eagle/kafka-eagle-web-xxx
export PATH=$KE_HOME/bin:$PATH</pre>
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-green-600">4. 修改配置</h4>
                                <div class="code-block">
                                    <pre># 设置集群名和zookeeper集群列表
kafka.eagle.zk.cluster.alias=cluster1
cluster1.zk.list=xxx:2181,xxx2181,,,,,,

# Kafka Eagle的页面访问端口
kafka.eagle.webui.port=8048

# 存储消费信息的类型
cluster1.kafka.eagle.offset.storage=kafka

# 存储Kafka Eagle元数据信息的数据库
kafka.eagle.driver=com.mysql.jdbc.Driver
kafka.eagle.url=jdbc:mysql://127.0.0.1:3306/ke?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
kafka.eagle.username=root
kafka.eagle.password=123456</pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Acknowledgements Section -->
        <section id="ack" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">Kafka应答机制</h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card bg-white p-6">
                    <h3 class="text-xl font-semibold mb-4 text-center">ACK=0</h3>
                    <div class="text-center mb-4">
                        <div class="inline-flex items-center justify-center w-16 h-16 bg-red-100 text-red-600 rounded-full">
                            <i class="fas fa-bolt text-2xl"></i>
                        </div>
                    </div>
                    <p class="text-gray-700 mb-3">生产者发送过来的数据，不需要等数据落盘应答。</p>
                    <div class="bg-red-50 p-3 rounded">
                        <p class="text-red-700 text-sm font-medium">数据可靠性：低</p>
                        <p class="text-red-700 text-sm">Leader没有接收到数据时，生产者已认为发送成功，容易丢数据。</p>
                    </div>
                </div>
                
                <div class="card bg-white p-6">
                    <h3 class="text-xl font-semibold mb-4 text-center">ACK=1</h3>
                    <div class="text-center mb-4">
                        <div class="inline-flex items-center justify-center w-16 h-16 bg-yellow-100 text-yellow-600 rounded-full">
                            <i class="fas fa-shield-alt text-2xl"></i>
                        </div>
                    </div>
                    <p class="text-gray-700 mb-3">生产者发送过来的数据，Leader收到数据后应答。</p>
                    <div class="bg-yellow-50 p-3 rounded">
                        <p class="text-yellow-700 text-sm font-medium">数据可靠性：中</p>
                        <p class="text-yellow-700 text-sm">Leader应答后故障，还未同步副本时，新Leader会丢失数据。</p>
                    </div>
                </div>
                
                <div class="card bg-white p-6">
                    <h3 class="text-xl font-semibold mb-4 text-center">ACK=-1 (all)</h3>
                    <div class="text-center mb-4">
                        <div class="inline-flex items-center justify-center w-16 h-16 bg-green-100 text-green-600 rounded-full">
                            <i class="fas fa-lock text-2xl"></i>
                        </div>
                    </div>
                    <p class="text-gray-700 mb-3">生产者发送过来的数据，Leader和ISR队列所有节点收齐数据后应答。</p>
                    <div class="bg-green-50 p-3 rounded">
                        <p class="text-green-700 text-sm font-medium">数据可靠性：高</p>
                        <p class="text-green-700 text-sm">所有副本都保存数据后才确认，最可靠但性能略低。</p>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 card bg-white p-6">
                <h3 class="text-xl font-semibold mb-4 flex items-center">
                    <div class="icon-box bg-purple-100 text-purple-600 mr-4">
                        <i class="fas fa-users"></i>
                    </div>
                    <span>ISR机制</span>
                </h3>
                
                <p class="text-gray-700 mb-4">ISR(in-sync replica set)机制是指和Leader保持同步的Follower集合。如果Follower长时间未向Leader发送通信请求或同步数据，则该Follower将被踢出ISR。该时间阈值由<code class="bg-purple-100 text-purple-800 px-1 rounded">replica.lag.time.max.ms</code>参数设定，默认30s。</p>
                
                <div class="diagram-container">
                    <div class="mermaid">
                        graph TB
                            Leader[Leader Partition] -->|同步| F1[Follower 1 - ISR]
                            Leader -->|同步| F2[Follower 2 - ISR]
                            Leader -->|超时未同步| F3[Follower 3 - 非ISR]
                    </div>
                </div>
            </div>
        </section>

        <!-- Message Acknowledgement Section -->
        <section id="message-ack" class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">消息消费确认机制</h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card bg-white p-6 mb-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-blue-100 text-blue-600 mr-4">
                                <i class="fas fa-sync"></i>
                            </div>
                            <span>偏移量分析</span>
                        </h3>
                        
                        <p class="text-gray-700 mb-4">在消费过程中，顺利完成消费后，会将消费的消息偏移量提交到Broker，Zookeeper中会存储对应偏移量，如果偏移量没有提交，那么可能会造成一条消息多次消费。</p>
                        
                        <div class="diagram-container">
                            <div class="mermaid">
                                graph LR
                                    Producer -->|发送消息| Broker
                                    Broker -->|存储消息| Partition
                                    Consumer -->|消费消息| Broker
                                    Consumer -->|提交偏移量| Broker
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-green-100 text-green-600 mr-4">
                                <i class="fas fa-robot"></i>
                            </div>
                            <span>自动提交</span>
                        </h3>
                        
                        <div class="space-y-4">
                            <p class="text-gray-700">自动提交模式下，消费者消费一条消息后，会自动将消息偏移量提交到服务器端，不需要手动进行确认。</p>
                            
                            <div class="code-block">
                                <pre>spring:
  kafka:
    consumer:
      enable-auto-commit: true # 是否自动提交offset
      auto-commit-interval: 120000 # 提交间隔(毫秒)
      auto-offset-reset: latest</pre>
                            </div>
                            
                            <div class="bg-yellow-50 p-4 rounded">
                                <h4 class="font-medium text-yellow-800 mb-2">优缺点</h4>
                                <div class="flex items-start mb-2">
                                    <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                    <span class="text-gray-700">操作简单，实现容易</span>
                                </div>
                                <div class="flex items-start">
                                    <i class="fas fa-exclamation-circle text-red-500 mt-1 mr-2"></i>
                                    <span class="text-gray-700">可能导致消息重复消费(服务异常时偏移量未提交)</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <div class="icon-box bg-purple-100 text-purple-600 mr-4">
                                <i class="fas fa-hand-paper"></i>
                            </div>
                            <span>手动提交</span>
                        </h3>
                        
                        <div class="space-y-4">
                            <p class="text-gray-700">手动确认模式下，消费者需要显式地调用commit()方法将消息的偏移量提交到服务器端，才会被标记为已处理。</p>
                            
                            <div class="code-block">
                                <pre>spring:
  kafka:
    consumer:
      enable-auto-commit: false # 关闭自动提交
    listener:
      ack-mode: manual # 手动提交模式</pre>
                            </div>
                            
                            <div class="code-block">
                                <pre>@KafkaListener(topics = "itmentu", groupId = "itmentuGroup")
public void listener(ConsumerRecord&lt;String,String&gt; record, Acknowledgment ack){
    // 处理消息逻辑
    ack.acknowledge(); // 手动提交偏移量
}</pre>
                            </div>
                            
                            <div class="bg-green-50 p-4 rounded">
                                <h4 class="font-medium text-green-800 mb-2">提交模式对比</h4>
                                <table class="w-full text-sm">
                                    <thead>
                                        <tr class="border-b">
                                            <th class="text-left py-2">模式</th>
                                            <th class="text-left py-2">描述</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="border-b">
                                            <td class="py-2">MANUAL</td>
                                            <td class="py-2">处理完业务后手动提交，偏移量先缓存再批量提交</td>
                                        </tr>
                                        <tr class="border-b">
                                            <td class="py-2">MANUAL_IMMEDIATE</td>
                                            <td class="py-2">处理完后立即提交</td>
                                        </tr>
                                        <tr>
                                            <td class="py-2">RECORD</td>
                                            <td class="py-2">每条记录处理后提交</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-semibold text-white mb-2">技术小馆</h3>
                    <p>探索技术，分享知识</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition">http://www.yuque.com/jtostring</a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-6 pt-6 text-sm text-center text-gray-500">
                &copy; 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```